package mms.swordsmithcraft.item;

import mms.swordsmithcraft.api.SwordAttribute;
import mms.swordsmithcraft.common.Type;
import net.minecraft.entity.Entity;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.world.World;
import org.lwjgl.Sys;

import static mms.swordsmithcraft.common.Type.dagger;

public class ItemWeaponBasic extends ItemSword implements SwordAttribute {
    private Type Itemtype;
    int i = 1;

    public ItemWeaponBasic(ToolMaterial p_i45356_1_, Type type) {
        super(p_i45356_1_);
        this.Itemtype = type;
    }

    @Override
    public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) {
        switch (this.Itemtype) {
            case sword:
                break;
            case dagger:
                break;
            case straight_sword:
                break;
            case long_sword:
                break;
            case japanese_sword:
                break;
        }
        return super.onLeftClickEntity(stack, player, entity);
    }

    @Override
    public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_) {
        switch (this.Itemtype) {
            case sword:
               p_77659_3_.setItemInUse(p_77659_1_, 1);
                break;
            case dagger:
                break;
            case straight_sword:
                break;
            case long_sword:
                break;
            case japanese_sword:
                break;
        }
        
        return p_77659_1_;
    }
	@Override
	public void onUsingTick(ItemStack stack, EntityPlayer player, int count) {
		super.onUsingTick(stack, player, count);
		 i++;
		System.out.println(i);
	}
    @Override
    public void onPlayerStoppedUsing(ItemStack p_77615_1_, World p_77615_2_, EntityPlayer p_77615_3_, int p_77615_4_) {
        i = 1;
        System.out.println("使用结束");
    }

    @Override
    public Type getType() {
        return Itemtype;
    }
    
    @Override
    public int getDamage(ItemStack item){
    	NBTTagCompound nbt = getOrCreateNbtData(item);
		return nbt.getInteger("Amount");
		}
    protected static void updateAttributes(NBTTagCompound nbtData) {
        // boolean active = nbtData.getBoolean("active");
        // int damage = active?5:0;
        NBTTagCompound entry = new NBTTagCompound();
        entry.setString("AttributeName", SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName());
        entry.setLong("UUIDMost", field_111210_e.getMostSignificantBits());
        entry.setLong("UUIDLeast", field_111210_e.getLeastSignificantBits());
        entry.setString("Name", "Tool modifier");
        entry.setDouble("Amount", (double) 5);
        entry.setInteger("Operation", 0);
        NBTTagList list = new NBTTagList();
        list.appendTag(entry);
        nbtData.setTag("AttributeModifiers", list);
        NBTTagCompound entry1 = new NBTTagCompound();
        entry1.setInteger("ForgingLevel", 0);
        entry1.setInteger("Quality", 0);
        entry1.setInteger("BladeSpeed", 0);
        entry1.setInteger("CloseSpeed", 0);
        entry1.setInteger("ContinuedStrength", 0);
        NBTTagList list1 = new NBTTagList();
        list1.appendTag(entry1);
        nbtData.setTag("WeaponSet", list1);
    }

    /**
     * 取物品NBT
     *
     * @return 该Itemstack的NBT
     */
    public static NBTTagCompound getOrCreateNbtData(ItemStack itemStack) {
        NBTTagCompound ret = itemStack.getTagCompound();
        if (ret == null) {
            ret = new NBTTagCompound();
            itemStack.setTagCompound(ret);
        }
        return ret;
    }

    @Override
    public int getQuality(ItemStack item) {
        NBTTagCompound nbt = getOrCreateNbtData(item);
        return nbt.getInteger("Quality");
    }

    @Override
    public int getForgingLevel(ItemStack item) {
        NBTTagCompound nbt = getOrCreateNbtData(item);
        return nbt.getInteger("ForgingLevel");
    }

    @Override
    public float getBladeSpeed(ItemStack item) {
        NBTTagCompound nbt = getOrCreateNbtData(item);
        return nbt.getInteger("BladeSpeed");
    }

    @Override
    public float getCloseSpeed(ItemStack item) {
        NBTTagCompound nbt = getOrCreateNbtData(item);
        return nbt.getInteger("CloseSpeed");
    }

    @Override
    public int getContinuedStrength(ItemStack item) {
        NBTTagCompound nbt = getOrCreateNbtData(item);
        return nbt.getInteger("ContinuedStrength");
    }


}
